﻿using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Xml.Serialization;

namespace DCSoft.TemperatureChart
{
    /// <summary>
    /// 网格线标题行信息
    /// </summary>
    /// <remarks></remarks>
    [Serializable]
    [System.Xml.Serialization.XmlType]
    [ComVisible(false)]
    public class TitleLineInfo
    {
        /// <summary>
        /// 初始化对象
        /// </summary>
        public TitleLineInfo()
        {
        }

        /// <summary>
        /// 初始化对象
        /// </summary>
        /// <param name="text"></param>
        /// <param name="dtmStart"></param>
        /// <param name="style"></param>
        /// <param name="startDateKeyword"></param>
        public TitleLineInfo(string text, DateTime dtmStart , TitleLineValueType style , string startDateKeyword )
        {
            Text = text;
            StartDate = dtmStart;
            ValueType = style;
            StartDateKeyword = startDateKeyword;
        }

        /// <summary>
        /// 初始化对象
        /// </summary>
        /// <param name="text"></param>
        /// <param name="dtmStart"></param>
        /// <param name="style"></param>
        /// <param name="startDateKeyword"></param>
        public TitleLineInfo(string text, DateTime dtmStart, TitleLineValueType style )
        {
            Text = text;
            StartDate = dtmStart;
            ValueType = style;
        }

        private string _Text = null;
        /// <summary>
        /// 标题文本
        /// </summary>
        [DefaultValue( null )]
        public string Text
        {
            get
            {
                return _Text; 
            }
            set
            {
                _Text = value; 
            }
        }

        private DateTime _StartDate = TemperatureDocument.NullDate;
        /// <summary>
        /// 开始计算的日期
        /// </summary>
        [DefaultValue( typeof( DateTime ) , TemperatureDocument.NullDateString )]
        public DateTime StartDate
        {
            get
            {
                return _StartDate; 
            }
            set
            {
                _StartDate = value; 
            }
        }

        private string _StartDateKeyword = null;
        /// <summary>
        /// 判断开始计算日期的关键字
        /// </summary>
        [DefaultValue( null )]
        public string StartDateKeyword
        {
            get
            {
                return _StartDateKeyword; 
            }
            set
            {
                _StartDateKeyword = value; 
            }
        }

        private DateTime _RuntimeStartDate = TemperatureDocument.NullDate;
        /// <summary>
        /// 运行时使用的开始计算的日期
        /// </summary>
        [Browsable(false)]
        [XmlIgnore]
        public DateTime RuntimeStartDate
        {
            get
            {
                return _RuntimeStartDate; 
            }
            set
            {
                _RuntimeStartDate = value; 
            }
        }

        private TitleLineValueType _ValueType = TitleLineValueType.SerialDate;
        /// <summary>
        /// 样式
        /// </summary>
        [DefaultValue( TitleLineValueType.SerialDate )]
        public TitleLineValueType ValueType
        {
            get
            {
                return _ValueType; 
            }
            set
            {
                _ValueType = value; 
            }
        }

        /// <summary>
        /// 标题行在文档视图中的Y坐标值
        /// </summary>
        [NonSerialized]
        internal float Top = float.NaN;

        internal string GetText(FooterMeasure cm)
        {
            switch (ValueType)
            {
                case TitleLineValueType.Abdomen_Circumference:
                    return cm.Abdomen_Circumference;
                case TitleLineValueType.Blood_PressureA:
                    return cm.Blood_PressureA;
                case TitleLineValueType.Blood_PressureP:
                    return cm.Blood_PressureP;
                case TitleLineValueType.Body_Weight:
                    return cm.Body_Weight;
                case TitleLineValueType.Liquid_In:
                    return cm.Liquid_In;
                case TitleLineValueType.Liquid_Out:
                    return cm.Liquid_Out;
                case TitleLineValueType.Pee:
                    return cm.Pee;
                case TitleLineValueType.Stool:
                    return cm.Stool;
            }
            return null;
        }
    }
}
